
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/06/2012 09:31:20
-- Generated from EDMX file: C:\Users\wei\Documents\Visual Studio 2010\Projects\TestAzure\WCFServiceWebRole1\azzModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [romaDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ProjectUserRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoleSet] DROP CONSTRAINT [FK_ProjectUserRole];
GO
IF OBJECT_ID(N'[dbo].[FK_UserUserRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoleSet] DROP CONSTRAINT [FK_UserUserRole];
GO
IF OBJECT_ID(N'[dbo].[FK_UserTimeReport]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TimeReportSet] DROP CONSTRAINT [FK_UserTimeReport];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectTimeReport]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TimeReportSet] DROP CONSTRAINT [FK_ProjectTimeReport];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSet];
GO
IF OBJECT_ID(N'[dbo].[UserRoleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRoleSet];
GO
IF OBJECT_ID(N'[dbo].[TimeReportSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TimeReportSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Username] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Pay] int  NOT NULL,
    [Role] int  NOT NULL
);
GO

-- Creating table 'ProjectSet'
CREATE TABLE [dbo].[ProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UserRoleSet'
CREATE TABLE [dbo].[UserRoleSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Role] int  NOT NULL,
    [Project_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'TimeReportSet'
CREATE TABLE [dbo].[TimeReportSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Start] datetime  NOT NULL,
    [Stop] datetime  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [User_Id] int  NOT NULL,
    [Project_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [PK_ProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserRoleSet'
ALTER TABLE [dbo].[UserRoleSet]
ADD CONSTRAINT [PK_UserRoleSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TimeReportSet'
ALTER TABLE [dbo].[TimeReportSet]
ADD CONSTRAINT [PK_TimeReportSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Project_Id] in table 'UserRoleSet'
ALTER TABLE [dbo].[UserRoleSet]
ADD CONSTRAINT [FK_ProjectUserRole]
    FOREIGN KEY ([Project_Id])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectUserRole'
CREATE INDEX [IX_FK_ProjectUserRole]
ON [dbo].[UserRoleSet]
    ([Project_Id]);
GO

-- Creating foreign key on [User_Id] in table 'UserRoleSet'
ALTER TABLE [dbo].[UserRoleSet]
ADD CONSTRAINT [FK_UserUserRole]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserRole'
CREATE INDEX [IX_FK_UserUserRole]
ON [dbo].[UserRoleSet]
    ([User_Id]);
GO

-- Creating foreign key on [User_Id] in table 'TimeReportSet'
ALTER TABLE [dbo].[TimeReportSet]
ADD CONSTRAINT [FK_UserTimeReport]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserTimeReport'
CREATE INDEX [IX_FK_UserTimeReport]
ON [dbo].[TimeReportSet]
    ([User_Id]);
GO

-- Creating foreign key on [Project_Id] in table 'TimeReportSet'
ALTER TABLE [dbo].[TimeReportSet]
ADD CONSTRAINT [FK_ProjectTimeReport]
    FOREIGN KEY ([Project_Id])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectTimeReport'
CREATE INDEX [IX_FK_ProjectTimeReport]
ON [dbo].[TimeReportSet]
    ([Project_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------